<%--
  Created by IntelliJ IDEA.
  User: Mr.G
  Date: 2019/1/11
  Time: 10:44
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html>
<head>
    <title>Title</title>
    <%@include file="/WEB-INF/jsp/common.jsp"%>
</head>
<body>
<div class="layui-fluid">
    <h2>诊断录入</h2>
    <hr>
    <div class="layui-row">
        <div class="layui-col-sm4">
            <table id="zhenduan" lay-filter="zhenduan"></table>
        </div>
        <div class="layui-col-sm7 layui-col-sm-offset1">
            <form class="layui-form" action="" lay-filter="zhiliaoform" id="zhiliaoform">
                <table class="layui-table">
                    <tbody>
                    <input type="hidden" id="bianhao" name="caseId"  class="layui-input">
                    <input type="hidden" id="userid" name="userId.userid" :value="userid"  class="layui-input">
                    <tr>
                        <td>病例编号:</td>
                        <td>
                            <select name="memberCaseNo.medicalRecordNo" id="medicalRecordNo" lay-filter="uu" lay-verify="required" lay-search="">
                                <option value="">直接选择或搜索选择</option>
                            </select>
                        </td>
                        <td>客户编号:</td>
                        <td><input type="text" id="memberId" name="memberId.cardMemberId" class="layui-input"></td>
                    </tr>
                    <tr>
                        <td>治疗开始时间:</td>
                        <td><input type="text" id="treatmentStartTime" name="stateData"  lay-verify="date" placeholder="H点m分" autocomplete="off" class="layui-input"></td>
                        <td>治疗结束时间:</td>
                        <td><input type="text" id="treatmentFinishTime" name="endData" lay-verify="date" placeholder="H点m分" autocomplete="off" class="layui-input"></td>
                    </tr>
                    <tr>
                        <td>治疗状态:</td>
                        <td> <select id="caseStatus" lay-filter="caseStatus" name="caseStatus">
                            <option value="1">正常</option>
                            <option value="0" selected>异常</option>
                        </select>
                        </td>
                    </tr>
                    <tr>
                        <td>主诉:</td>
                        <td colspan="5"><textarea disabled name="caseTell" id="treatmentRemark"  lay-verify="required" placeholder="请输入" class="layui-textarea layui-disabled"></textarea></td>
                        <input type="hidden" name="caseTell">
                    </tr>
                    <tr>
                        <td>案例分析:</td>
                        <td colspan="5"><textarea disabled name="caseReview" id="caseReview"  lay-verify="required" placeholder="请输入" class="layui-textarea layui-disabled"></textarea></td>
                        <input type="hidden" name="caseReview">
                    </tr>
                    <tr>
                        <td>治疗师检查结果:</td>
                        <td colspan="5"><textarea name="caseTest" id="caseTell"  lay-verify="required" placeholder="请输入" class="layui-textarea"></textarea></td>
                    </tr>
                    </tbody>
                </table>
                <div class="layui-upload">
                    <button type="button" class="layui-btn" id="test2">治疗图片上传</button>
                    <button type="button" class="layui-btn" onclick="Xxiugai()"  id="tijiao">提交</button>

                    <input type="hidden" name="imgpath" id="imgpath">
                    <blockquote class="layui-elem-quote layui-quote-nm" style="margin-top: 10px;">
                        预览图：
                        <div class="layui-upload-list" id="demo2"></div>
                    </blockquote>
                </div>

            </form>
        </div>
    </div>
</div>
<script>
    layui.config({
        base: '${path}/assets/layui/lay/modules/'
    }).extend({
        notice : 'notice'
    })

    var table;
    var form ;
    var laydate;
    var notice;
    var upload;


    var pathimg ;

    layui.use(['table','form','laydate','notice','upload'],function () {
        table = layui.table;
        form = layui.form;
        laydate = layui.laydate;
        notice = layui.notice;
        upload = layui.upload;

        //渲染表格
        table.render({
            elem: '#zhenduan',
            url: '${path}/case/zhenduanluru',
            even: true,
            cols:[[
                {type:'radio'},
                {field:'memberCaseNo',title:'病历号',templet:function (d) {
                        return d.memberCaseNo.medicalRecordNo
                    }},
                {field:'memberId',title:'患者姓名',templet:function (d) {
                        return d.memberCaseNo.reserveName
                    }},
                {field:'memberId',title:'预约仪器',templet:function (d) {

                    if (d.reserveInstr == null || d.reserveInstr.length == 0){
                       return "未预约治疗仪"
                    }
                        var str = "";
                        for (var i = 0; i<d.reserveInstr.length;i++){
                            str += d.reserveInstr[i].instrId.instrName;
                            if (i != d.reserveInstr.length-1){
                                str += "|"
                            }
                        }
                        return str;
                    }}
            ]]
        })

        //监听单选框选中事件
        table.on('radio(zhenduan)',function (obj) {
            console.log(obj)
            $.get("${path}/bingliluru/getCaseInfoById",{memberCaseNo:obj.data.memberCaseNo.medicalRecordNo},function (getstr) {
                getstr["memberCaseNo.medicalRecordNo"] = getstr.memberCaseNo.medicalRecordNo;
                getstr["memberId.cardMemberId"] = getstr.memberId.cardMemberId;
                getstr["userId.userid"] = getstr.userId.userid;
                form.val('zhiliaoform',getstr);
                form.render("select")
            })

        })

        //取出病例列表
        $.get('${path}/bingliluru/getjiuzhen',function (data) {
            $.each(data,function(){
                var opt = $("<option></option>").appendTo("#medicalRecordNo");
                opt.text(this.medicalRecordNo).val(this.medicalRecordNo);
            });
            layui.form.render();
        });



        upload.render({
            elem: '#test2'
            ,url: '${path}/bingliluru/filesUpload'
            ,multiple: true
            ,before: function(obj){
                //预读本地文件示例，不支持ie8
                obj.preview(function(index, file, result){
                    $('#demo2').append('<img width="100px" src="'+ result +'" alt="'+ file.name +'" class="layui-upload-img">')
                });
                pathimg = "";
            }
            ,done: function(res){
                pathimg += res.imgPath+"-";
                console.log(pathimg);
                $("#imgpath").val(pathimg);

            }
        });
    })
    //提交
    function Xxiugai() {
        var parems = $("#zhiliaoform").serialize();
        $.get("${path}/bingliluru/editCaseInfo",parems,function (data) {
            form.val('zhiliaoform',null);

            table.reload("bingliluru")
            layui.notice.init({
                type: "default",
                autoClose: true,
                title: "完成治疗成功！"
            });
        })

    }
</script>
</body>
</html>
